/**
 * @constructor: 张提通;
 * @param: {event:粘贴事件};
 * @name:读取剪切板图片并返回Base64url;
 */

export function handlePaste(event) {
	return new Promise((resolve, reject) => {
		const clipboardData = event.clipboardData || window.clipboardData
		if (clipboardData) {
			let url = ''
			for (let i = 0; i < clipboardData.items.length; i++) {
				const item = clipboardData.items[i]
				if (item.kind === 'file' && item.type.startsWith('image/')) {
					const file = item.getAsFile()
					if (file) {
						const reader = new FileReader()
						// reader.readAsDataURL(file)

						reader.onload = (e) => {
							console.log('图片的Base64：', e.target.result)
							// url = e.target.result
						}
						reader.readAsDataURL(file)

						reader.onloadend = (e) => {
							url = reader.result
							resolve(url)
						}
					}
				}
			}
		}
	})
}
